const shsDB = require("../../db");

/**添加ip地址
 * @param {object} req 
 * @param {int} userid
 * @param {string} ip 
 * @param {string} status 状态 
 * @param {string} details 备注
 * 
 */
function addOnlineRecorder(userid,req,details="",status=0,ip='') {
	try{
		if(!userid) return
		if(req){
			ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
		}
		let nowDate = getdate();
		let sql=`INSERT INTO \`imdb\`.\`online\`(\`onlineID\`, \`userID\`, \`details\`, \`ip\`,\`status\`, \`createTime\`, \`updateTime\`)
		 VALUES (null, '${userid}', '${details}', '${ip}','${status}', '${nowDate}', '${nowDate}');`
		shsDB(sql)
	}catch(e){
		console.log("err online",e.message);
	}

}

module.exports = addOnlineRecorder